# All relevant packages
packages <- c("plyr", "dplyr", "data.table", "extrafont", "ggplot2", "sandwich",
              "gridExtra", "stats", "tidyverse", "survival", "strucchange", 
              "msm", "car", "stargazer", "MASS", "zoo", "AER", "broom", "xtable",
              "lmtest", "foreach", "doParallel", "scales", "quanteda", "forcats")

# Install packages not yet installed
installedPackages <- packages %in% rownames(installed.packages())
if (any(installedPackages == FALSE)) {
  install.packages(packages[!installedPackages])
}

# Load packages
invisible(lapply(packages, library, character.only = TRUE))